<script setup lang="ts">
import type { FormInstance } from 'element-plus'
import useLoginStore from '@/store/login/login'
import { rules } from '../config/phone-config'

const formRef = ref<FormInstance>()
const phone = reactive({
  num: '',
  code: ''
})

const loginStore = useLoginStore()

const loginAction = () => {
  formRef.value?.validate((valid) => {
    if (valid) {
      loginStore.phoneLoginAction({ ...phone })
    }
  })
}
defineExpose({ loginAction })
</script>
<template>
  <el-form ref="formRef" :model="phone" :rules="rules" label-width="70px">
    <el-form-item label="手机号" prop="num">
      <el-input v-model="phone.num" />
    </el-form-item>
    <el-form-item label="验证码" prop="code">
      <div class="get-code">
        <el-input v-model="phone.code" />
        <el-button type="primary" class="get-btn">获取验证码</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>

<style scoped>
.get-code {
  display: flex;
}

.get-btn {
  margin-left: 8px;
}
</style>
